<template>
  <div class="app-container">
    <!--日志登录-->
    <el-form ref="ruleForm" :inline="true"  :model="tbLoginLogVO" class="demo-form-inline">

      <el-form-item label="用户名" prop="username">
        <el-input style="width: 200px" v-model="tbLoginLogVO.username" placeholder="请输入用户名查询"></el-input>
      </el-form-item>

      <el-form-item label="IP地址" prop="ip">
        <el-input style="width: 200px" v-model="tbLoginLogVO.ip" placeholder="请输入IP查询"></el-input>
      </el-form-item>

      <el-form-item label="登入地址" prop="location">
        <el-input style="width: 200px" v-model="tbLoginLogVO.location" placeholder="请输入登入地址查询"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="logLists">查询</el-button>
        <el-button plain icon="el-icon-delete" @click="onDel">批量</el-button>
      </el-form-item>
    </el-form>

    <el-table
      ref="multipleTable"
      :data="LoginLog"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>

      <el-table-column
        prop="id"
        label="id"
        width="50">
      </el-table-column>

      <el-table-column
        prop="username"
        label="登入用户"
        width="120">
      </el-table-column>

      <el-table-column
        prop="loginTime"
        label="登入时间"
        width="120">
      </el-table-column>

      <el-table-column
        prop="location"
        label="登入地点"
        width="300">
      </el-table-column>

      <el-table-column
        prop="ip"
        label="IP地址"
        width="120">
      </el-table-column>

      <el-table-column
        prop="userSystem"
        label="操作系统"
        width="120">
      </el-table-column>

      <el-table-column
        prop="userBrowser"
        label="浏览器"
        width="120">
      </el-table-column>

      <el-table-column
        label="操作"
        width="120">
        <template slot-scope="scope">
        <el-button type="danger" icon="el-icon-delete" circle @click="del(scope.row.id)"></el-button>
        </template>
      </el-table-column>

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="current"
      :page-sizes="[7, 10, 15, 20]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

  </div>
</template>

<script>
  import {getlogList,dellogList,deleteplus} from '@/api/log'
    export default {
        name: "LoginLog",
      data(){

          return{
            multipleSelection: [],
            current: 1,
            size: 7,
            tbLoginLogVO: {
              username: '',
              ip: '',
              location: ''
            },
            total: 100,
            LoginLog: []
          }

      },
      created() {
        this.logLists();
      },
      methods: {
          //分页查询
        logLists() {
          getlogList(this.current, this.size, this.tbLoginLogVO).then(res => {
            this.LoginLog = res.data.records.records
            this.total = res.data.total
          })
            .catch(err => {
            })
        },
        //删除操作
        del(id) {
          dellogList(id).then(res => {
            this.logLists();
          })
            .catch(err => {
            })
        },
        handleSizeChange(val) {
          this.size = val;
          this.logLists();
        },
        handleCurrentChange(val) {
          this.current = val;
          this.logLists();

        },
        toggleSelection(rows) {
          if (rows) {
            rows.forEach(row => {
              this.$refs.multipleTable.toggleRowSelection(row);
            });
          } else {
            this.$refs.multipleTable.clearSelection();
          }
        },
        handleSelectionChange(val) {
          this.multipleSelection = val;
        },
        onDel(){
          var ids=[];
          for (let i = 0; i <this.multipleSelection.length ; i++) {
              ids[i]=this.multipleSelection[i].id
          }
          deleteplus(ids).then(res=>{
            console.log("ok")
            this.logLists();
          })
        }
      }
    }
</script>

<style scoped>

</style>
